home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / expr.test < prev    next >
Text File  |  1992-12-23  |  20KB  |  499 lines

  1. # Commands covered:  expr
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # $Header: /rel/cvsfiles/devo/tcl/tests/expr.test,v 1.1.1.1 1992/11/07 04:46:54 zoo Exp $ (Berkeley)
  8.  
  9. if {[string compare test [info procs test]] == 1} then {source defs}
  10.  
  11. # First, test all of the integer operators individually.
  12.  
  13. test expr-1.1 {integer operators} {expr -4} -4
  14. test expr-1.2 {integer operators} {expr -(1+4)} -5
  15. test expr-1.3 {integer operators} {expr ~3} -4
  16. test expr-1.4 {integer operators} {expr !2} 0
  17. test expr-1.5 {integer operators} {expr !0} 1
  18. test expr-1.6 {integer operators} {expr 4*6} 24
  19. test expr-1.7 {integer operators} {expr 36/12} 3
  20. test expr-1.8 {integer operators} {expr 27/4} 6
  21. test expr-1.9 {integer operators} {expr 27%4} 3
  22. test expr-1.10 {integer operators} {expr 2+2} 4
  23. test expr-1.11 {integer operators} {expr 2-6} -4
  24. test expr-1.12 {integer operators} {expr 1<<3} 8
  25. test expr-1.13 {integer operators} {expr 0xff>>2} 63
  26. test expr-1.14 {integer operators} {expr -1>>2} -1
  27. test expr-1.15 {integer operators} {expr 3>2} 1
  28. test expr-1.16 {integer operators} {expr 2>2} 0
  29. test expr-1.17 {integer operators} {expr 1>2} 0
  30. test expr-1.18 {integer operators} {expr 3<2} 0
  31. test expr-1.19 {integer operators} {expr 2<2} 0
  32. test expr-1.20 {integer operators} {expr 1<2} 1
  33. test expr-1.21 {integer operators} {expr 3>=2} 1
  34. test expr-1.22 {integer operators} {expr 2>=2} 1
  35. test expr-1.23 {integer operators} {expr 1>=2} 0
  36. test expr-1.24 {integer operators} {expr 3<=2} 0
  37. test expr-1.25 {integer operators} {expr 2<=2} 1
  38. test expr-1.26 {integer operators} {expr 1<=2} 1
  39. test expr-1.27 {integer operators} {expr 3==2} 0
  40. test expr-1.28 {integer operators} {expr 2==2} 1
  41. test expr-1.29 {integer operators} {expr 3!=2} 1
  42. test expr-1.30 {integer operators} {expr 2!=2} 0
  43. test expr-1.31 {integer operators} {expr 7&0x13} 3
  44. test expr-1.32 {integer operators} {expr 7^0x13} 20
  45. test expr-1.33 {integer operators} {expr 7|0x13} 23
  46. test expr-1.34 {integer operators} {expr 0&&1} 0
  47. test expr-1.35 {integer operators} {expr 0&&0} 0
  48. test expr-1.36 {integer operators} {expr 1&&3} 1
  49. test expr-1.37 {integer operators} {expr 0||1} 1
  50. test expr-1.38 {integer operators} {expr 3||0} 1
  51. test expr-1.39 {integer operators} {expr 0||0} 0
  52. test expr-1.40 {integer operators} {expr 3>2?44:66} 44
  53. test expr-1.41 {integer operators} {expr 2>3?44:66} 66
  54.  
  55. # Check the floating-point operators individually, along with
  56. # automatic conversion to integers where needed.
  57.  
  58. test expr-2.1 {floating-point operators} {expr -4.2} -4.2
  59. test expr-2.2 {floating-point operators} {expr -(1.1+4.2)} -5.3
  60. test expr-2.3 {floating-point operators} {expr !2.1} 0
  61. test expr-2.4 {floating-point operators} {expr !0.0} 1
  62. test expr-2.5 {floating-point operators} {expr 4.2*6.3} 26.46
  63. test expr-2.6 {floating-point operators} {expr 36.0/12.0} 3
  64. test expr-2.7 {floating-point operators} {expr 27/4.0} 6.75
  65. test expr-2.8 {floating-point operators} {expr 2.3+2.1} 4.4
  66. test expr-2.9 {floating-point operators} {expr 2.3-6.5} -4.2
  67. test expr-2.10 {floating-point operators} {expr 3.1>2.1} 1
  68. test expr-2.11 {floating-point operators} {expr {2.1 > 2.1}} 0
  69. test expr-2.12 {floating-point operators} {expr 1.23>2.34e+1} 0
  70. test expr-2.13 {floating-point operators} {expr 3.45<2.34} 0
  71. test expr-2.14 {floating-point operators} {expr 0.002e3<--200e-2} 0
  72. test expr-2.15 {floating-point operators} {expr 1.1<2.1} 1
  73. test expr-2.16 {floating-point operators} {expr 3.1>=2.2} 1
  74. test expr-2.17 {floating-point operators} {expr 2.345>=2.345} 1
  75. test expr-2.18 {floating-point operators} {expr 1.1>=2.2} 0
  76. test expr-2.19 {floating-point operators} {expr 3.0<=2.0} 0
  77. test expr-2.20 {floating-point operators} {expr 2.2<=2.2} 1
  78. test expr-2.21 {floating-point operators} {expr 2.2<=2.2001} 1
  79. test expr-2.22 {floating-point operators} {expr 3.2==2.2} 0
  80. test expr-2.23 {floating-point operators} {expr 2.2==2.2} 1
  81. test expr-2.24 {floating-point operators} {expr 3.2!=2.2} 1
  82. test expr-2.25 {floating-point operators} {expr 2.2!=2.2} 0
  83. test expr-2.26 {floating-point operators} {expr 0.0&&0.0} 0
  84. test expr-2.27 {floating-point operators} {expr 0.0&&1.3} 0
  85. test expr-2.28 {floating-point operators} {expr 1.3&&0.0} 0
  86. test expr-2.29 {floating-point operators} {expr 1.3&&3.3} 1
  87. test expr-2.30 {floating-point operators} {expr 0.0||0.0} 0
  88. test expr-2.31 {floating-point operators} {expr 0.0||1.3} 1
  89. test expr-2.32 {floating-point operators} {expr 1.3||0.0} 1
  90. test expr-2.33 {floating-point operators} {expr 3.3||0.0} 1
  91. test expr-2.34 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
  92. test expr-2.35 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
  93.  
  94. # Operators that aren't legal on floating-point numbers
  95.  
  96. test expr-3.1 {illegal floating-point operations} {
  97.     list [catch {expr ~4.0} msg] $msg
  98. } {1 {can't use floating-point value as operand of "~"}}
  99. test expr-3.2 {illegal floating-point operations} {
  100.     list [catch {expr 27%4.0} msg] $msg
  101. } {1 {can't use floating-point value as operand of "%"}}
  102. test expr-3.3 {illegal floating-point operations} {
  103.     list [catch {expr 27.0%4} msg] $msg
  104. } {1 {can't use floating-point value as operand of "%"}}
  105. test expr-3.4 {illegal floating-point operations} {
  106.     list [catch {expr 1.0<<3} msg] $msg
  107. } {1 {can't use floating-point value as operand of "<<"}}
  108. test expr-3.5 {illegal floating-point operations} {
  109.     list [catch {expr 3<<1.0} msg] $msg
  110. } {1 {can't use floating-point value as operand of "<<"}}
  111. test expr-3.6 {illegal floating-point operations} {
  112.     list [catch {expr 24.0>>3} msg] $msg
  113. } {1 {can't use floating-point value as operand of ">>"}}
  114. test expr-3.7 {illegal floating-point operations} {
  115.     list [catch {expr 24>>3.0} msg] $msg
  116. } {1 {can't use floating-point value as operand of ">>"}}
  117. test expr-3.8 {illegal floating-point operations} {
  118.     list [catch {expr 24&3.0} msg] $msg
  119. } {1 {can't use floating-point value as operand of "&"}}
  120. test expr-3.9 {illegal floating-point operations} {
  121.     list [catch {expr 24.0|3} msg] $msg
  122. } {1 {can't use floating-point value as operand of "|"}}
  123. test expr-3.10 {illegal floating-point operations} {
  124.     list [catch {expr 24.0^3} msg] $msg
  125. } {1 {can't use floating-point value as operand of "^"}}
  126.  
  127. # Check the string operators individually.
  128.  
  129. test expr-4.1 {string operators} {expr {"abc" > "def"}} 0
  130. test expr-4.2 {string operators} {expr {"def" > "def"}} 0
  131. test expr-4.3 {string operators} {expr {"g" > "def"}} 1
  132. test expr-4.4 {string operators} {expr {"abc" < "abd"}} 1
  133. test expr-4.5 {string operators} {expr {"abd" < "abd"}} 0
  134. test expr-4.6 {string operators} {expr {"abe" < "abd"}} 0
  135. test expr-4.7 {string operators} {expr {"abc" >= "def"}} 0
  136. test expr-4.8 {string operators} {expr {"def" >= "def"}} 1
  137. test expr-4.9 {string operators} {expr {"g" >= "def"}} 1
  138. test expr-4.10 {string operators} {expr {"abc" <= "abd"}} 1
  139. test expr-4.11 {string operators} {expr {"abd" <= "abd"}} 1
  140. test expr-4.12 {string operators} {expr {"abe" <= "abd"}} 0
  141. test expr-4.13 {string operators} {expr {"abc" == "abd"}} 0
  142. test expr-4.14 {string operators} {expr {"abd" == "abd"}} 1
  143. test expr-4.15 {string operators} {expr {"abc" != "abd"}} 1
  144. test expr-4.16 {string operators} {expr {"abd" != "abd"}} 0
  145. test expr-4.17 {string operators} {expr {"0y" < "0x12"}} 1
  146. test expr-4.18 {string operators} {expr {1?"foo":"bar"}} foo
  147. test expr-4.19 {string operators} {expr {0?"foo":"bar"}} bar
  148.  
  149. # Operators that aren't legal on string operands.
  150.  
  151. test expr-5.1 {illegal string operations} {
  152.     list [catch {expr {-"a"}} msg] $msg
  153. } {1 {can't use non-numeric string as operand of "-"}}
  154. test expr-5.2 {illegal string operations} {
  155.     list [catch {expr {~"a"}} msg] $msg
  156. } {1 {can't use non-numeric string as operand of "~"}}
  157. test expr-5.3 {illegal string operations} {
  158.     list [catch {expr {!"a"}} msg] $msg
  159. } {1 {can't use non-numeric string as operand of "!"}}
  160. test expr-5.4 {illegal string operations} {
  161.     list [catch {expr {"a"*"b"}} msg] $msg
  162. } {1 {can't use non-numeric string as operand of "*"}}
  163. test expr-5.5 {illegal string operations} {
  164.     list [catch {expr {"a"/"b"}} msg] $msg
  165. } {1 {can't use non-numeric string as operand of "/"}}
  166. test expr-5.6 {illegal string operations} {
  167.     list [catch {expr {"a"%"b"}} msg] $msg
  168. } {1 {can't use non-numeric string as operand of "%"}}
  169. test expr-5.7 {illegal string operations} {
  170.     list [catch {expr {"a"+"b"}} msg] $msg
  171. } {1 {can't use non-numeric string as operand of "+"}}
  172. test expr-5.8 {illegal string operations} {
  173.     list [catch {expr {"a"-"b"}} msg] $msg
  174. } {1 {can't use non-numeric string as operand of "-"}}
  175. test expr-5.9 {illegal string operations} {
  176.     list [catch {expr {"a"<<"b"}} msg] $msg
  177. } {1 {can't use non-numeric string as operand of "<<"}}
  178. test expr-5.10 {illegal string operations} {
  179.     list [catch {expr {"a">>"b"}} msg] $msg
  180. } {1 {can't use non-numeric string as operand of ">>"}}
  181. test expr-5.11 {illegal string operations} {
  182.     list [catch {expr {"a"&"b"}} msg] $msg
  183. } {1 {can't use non-numeric string as operand of "&"}}
  184. test expr-5.12 {illegal string operations} {
  185.     list [catch {expr {"a"^"b"}} msg] $msg
  186. } {1 {can't use non-numeric string as operand of "^"}}
  187. test expr-5.13 {illegal string operations} {
  188.     list [catch {expr {"a"|"b"}} msg] $msg
  189. } {1 {can't use non-numeric string as operand of "|"}}
  190. test expr-5.14 {illegal string operations} {
  191.     list [catch {expr {"a"&&"b"}} msg] $msg
  192. } {1 {can't use non-numeric string as operand of "&&"}}
  193. test expr-5.15 {illegal string operations} {
  194.     list [catch {expr {"a"||"b"}} msg] $msg
  195. } {1 {can't use non-numeric string as operand of "||"}}
  196. test expr-5.16 {illegal string operations} {
  197.     list [catch {expr {"a"?4:2}} msg] $msg
  198. } {1 {can't use non-numeric string as operand of "?"}}
  199.  
  200. # Check precedence pairwise.
  201.  
  202. test expr-6.1 {precedence checks} {expr -~3} 4
  203. test expr-6.2 {precedence checks} {expr -!3} 0
  204. test expr-6.3 {precedence checks} {expr -~0} 1
  205.  
  206. test expr-7.1 {precedence checks} {expr 2*4/6} 1
  207. test expr-7.2 {precedence checks} {expr 24/6*3} 12
  208. test expr-7.3 {precedence checks} {expr 24/6/2} 2
  209.  
  210. test expr-8.1 {precedence checks} {expr -2+4} 2
  211. test expr-8.2 {precedence checks} {expr -2-4} -6
  212.  
  213. test expr-9.1 {precedence checks} {expr 2*3+4} 10
  214. test expr-9.2 {precedence checks} {expr 8/2+4} 8
  215. test expr-9.3 {precedence checks} {expr 8%3+4} 6
  216. test expr-9.4 {precedence checks} {expr 2*3-1} 5
  217. test expr-9.5 {precedence checks} {expr 8/2-1} 3
  218. test expr-9.6 {precedence checks} {expr 8%3-1} 1
  219.  
  220. test expr-10.1 {precedence checks} {expr 6-3-2} 1
  221.  
  222. test expr-11.1 {precedence checks} {expr 7+1>>2} 2
  223. test expr-11.2 {precedence checks} {expr 7+1<<2} 32
  224. test expr-11.3 {precedence checks} {expr 7>>3-2} 3
  225. test expr-11.4 {precedence checks} {expr 7<<3-2} 14
  226.  
  227. test expr-12.1 {precedence checks} {expr 6>>1>4} 0
  228. test expr-12.2 {precedence checks} {expr 6>>1<2} 0
  229. test expr-12.3 {precedence checks} {expr 6>>1>=3} 1
  230. test expr-12.4 {precedence checks} {expr 6>>1<=2} 0
  231. test expr-12.5 {precedence checks} {expr 6<<1>5} 1
  232. test expr-12.6 {precedence checks} {expr 6<<1<5} 0
  233. test expr-12.7 {precedence checks} {expr 5<=6<<1} 1
  234. test expr-12.8 {precedence checks} {expr 5>=6<<1} 0
  235.  
  236. test expr-13.1 {precedence checks} {expr 2<3<4} 1
  237. test expr-13.2 {precedence checks} {expr 0<4>2} 0
  238. test expr-13.3 {precedence checks} {expr 4>2<1} 0
  239. test expr-13.4 {precedence checks} {expr 4>3>2} 0
  240. test expr-13.5 {precedence checks} {expr 4>3>=2} 0
  241. test expr-13.6 {precedence checks} {expr 4>=3>2} 0
  242. test expr-13.7 {precedence checks} {expr 4>=3>=2} 0
  243. test expr-13.8 {precedence checks} {expr 0<=4>=2} 0
  244. test expr-13.9 {precedence checks} {expr 4>=2<=0} 0
  245. test expr-10.10 {precedence checks} {expr 2<=3<=4} 1
  246.  
  247. test expr-14.1 {precedence checks} {expr 1==4>3} 1
  248. test expr-14.2 {precedence checks} {expr 0!=4>3} 1
  249. test expr-14.3 {precedence checks} {expr 1==3<4} 1
  250. test expr-14.4 {precedence checks} {expr 0!=3<4} 1
  251. test expr-14.5 {precedence checks} {expr 1==4>=3} 1
  252. test expr-14.6 {precedence checks} {expr 0!=4>=3} 1
  253. test expr-14.7 {precedence checks} {expr 1==3<=4} 1
  254. test expr-14.8 {precedence checks} {expr 0!=3<=4} 1
  255.  
  256. test expr-15.1 {precedence checks} {expr 1==3==3} 0
  257. test expr-15.2 {precedence checks} {expr 3==3!=2} 1
  258. test expr-15.3 {precedence checks} {expr 2!=3==3} 0
  259. test expr-15.4 {precedence checks} {expr 2!=1!=1} 0
  260.  
  261. test expr-16.1 {precedence checks} {expr 2&3==2} 0
  262. test expr-16.2 {precedence checks} {expr 1&3!=3} 0
  263.  
  264. test expr-17.1 {precedence checks} {expr 7&3^0x10} 19
  265. test expr-17.2 {precedence checks} {expr 7^0x10&3} 7
  266.  
  267. test expr-18.1 {precedence checks} {expr 7^0x10|3} 23
  268. test expr-18.2 {precedence checks} {expr 7|0x10^3} 23
  269.  
  270. test expr-19.1 {precedence checks} {expr 7|3&&1} 1
  271. test expr-19.2 {precedence checks} {expr 1&&3|7} 1
  272. test expr-19.3 {precedence checks} {expr 0&&1||1} 1
  273. test expr-19.4 {precedence checks} {expr 1||1&&0} 1
  274.  
  275. test expr-20.1 {precedence checks} {expr 1||0?3:4} 3
  276. test expr-20.2 {precedence checks} {expr 1?0:4||1} 0
  277.  
  278. # Parentheses.
  279.  
  280. test expr-21.1 {parenthesization} {expr (2+4)*6} 36
  281. test expr-21.2 {parenthesization} {expr (1?0:4)||1} 1
  282.  
  283. # Embedded commands and variable names.
  284.  
  285. set a 16
  286. test expr-22.1 {embedded variables} {expr {2*$a}} 32
  287. test expr-22.2 {embedded variables} {
  288.     set x -5
  289.     set y 10
  290.     expr {$x + $y}
  291. } {5}
  292. test expr-22.3 {embedded commands and variables} {expr {[set a] - 14}} 2
  293. test expr-22.4 {embedded commands and variables} {
  294.     list [catch {expr {12 - [bad_command_name]}} msg] $msg
  295. } {1 {invalid command name: "bad_command_name"}}
  296.  
  297. # Double-quotes and things inside them.
  298.  
  299. test expr-23.1 {double-quotes} {expr {"abc"}} abc
  300. test expr-23.2 {double-quotes} {
  301.     set a 189
  302.     expr {"$a.bc"}
  303. } 189.bc
  304. test expr-23.3 {double-quotes} {
  305.     set b2 xyx
  306.     expr {"$b2$b2$b2.[set b2].[set b2]"}
  307. } xyxxyxxyx.xyx.xyx
  308. test expr-23.4 {double-quotes} {expr {"11\}\}22"}} 11}}22
  309. test expr-23.5 {double-quotes} {expr {"\abc"}} {\abc}
  310. test expr-23.6 {double-quotes} {
  311.     catch {unset bogus__}
  312.     list [catch {expr {"$bogus__"}} msg] $msg
  313. } {1 {can't read "bogus__": no such variable}}
  314. test expr-23.7 {double-quotes} {
  315.     list [catch {expr {"a[error Testing]bc"}} msg] $msg
  316. } {1 Testing}
  317.  
  318. # Numbers in various bases.
  319.  
  320. test expr-24.1 {numbers in different bases} {expr 0x20} 32
  321. test expr-24.2 {numbers in different bases} {expr 015} 13
  322.  
  323. # Conversions between various data types.
  324.  
  325. test expr-25.1 {type conversions} {expr 2+2.5} 4.5
  326. test expr-25.2 {type conversions} {expr 2.5+2} 4.5
  327. test expr-25.3 {type conversions} {expr 2-2.5} -0.5
  328. test expr-25.4 {type conversions} {expr 2/2.5} 0.8
  329. test expr-25.5 {type conversions} {expr 2>2.5} 0
  330. test expr-25.6 {type conversions} {expr 2.5>2} 1
  331. test expr-25.7 {type conversions} {expr 2<2.5} 1
  332. test expr-25.8 {type conversions} {expr 2>=2.5} 0
  333. test expr-25.9 {type conversions} {expr 2<=2.5} 1
  334. test expr-25.10 {type conversions} {expr 2==2.5} 0
  335. test expr-25.11 {type conversions} {expr 2!=2.5} 1
  336. test expr-25.12 {type conversions} {expr 2>"ab"} 0
  337. test expr-25.13 {type conversions} {expr {2>" "}} 1
  338. test expr-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
  339. test expr-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
  340. test expr-25.16 {type conversions} {expr 2+2.5} 4.5
  341. test expr-25.17 {type conversions} {expr 2+2.5} 4.5
  342.  
  343. # Various error conditions.
  344.  
  345. test expr-26.1 {error conditions} {
  346.     list [catch {expr 2+"a"} msg] $msg
  347. } {1 {can't use non-numeric string as operand of "+"}}
  348. test expr-26.2 {error conditions} {
  349.     list [catch {expr 2+4*} msg] $msg
  350. } {1 {syntax error in expression "2+4*"}}
  351. test expr-26.3 {error conditions} {
  352.     list [catch {expr 2+4*(} msg] $msg
  353. } {1 {syntax error in expression "2+4*("}}
  354. catch {unset _non_existent_}
  355. test expr-26.4 {error conditions} {
  356.     list [catch {expr 2+$_non_existent_} msg] $msg
  357. } {1 {can't read "_non_existent_": no such variable}}
  358. set a xx
  359. test expr-26.5 {error conditions} {
  360.     list [catch {expr {2+$a}} msg] $msg
  361. } {1 {can't use non-numeric string as operand of "+"}}
  362. test expr-26.6 {error conditions} {
  363.     list [catch {expr {2+[set a]}} msg] $msg
  364. } {1 {can't use non-numeric string as operand of "+"}}
  365. test expr-26.7 {error conditions} {
  366.     list [catch {expr {2+(4}} msg] $msg
  367. } {1 {unmatched parentheses in expression "2+(4"}}
  368. test expr-26.8 {error conditions} {
  369.     list [catch {expr 2/0} msg] $msg
  370. } {1 {divide by zero}}
  371. test expr-26.9 {error conditions} {
  372.     list [catch {expr 2%0} msg] $msg
  373. } {1 {divide by zero}}
  374. test expr-26.10 {error conditions} {
  375.     list [catch {expr 2#} msg] $msg
  376. } {1 {syntax error in expression "2#"}}
  377. test expr-26.11 {error conditions} {
  378.     list [catch {expr a.b} msg] $msg
  379. } {1 {syntax error in expression "a.b"}}
  380. test expr-26.12 {error conditions} {
  381.     list [catch {expr {"a"/"b"}} msg] $msg
  382. } {1 {can't use non-numeric string as operand of "/"}}
  383. test expr-26.13 {error conditions} {
  384.     list [catch {expr 2:3} msg] $msg
  385. } {1 {can't have : operator without ? first}}
  386. test expr-26.14 {error conditions} {
  387.     list [catch {expr a@b} msg] $msg
  388. } {1 {syntax error in expression "a@b"}}
  389. test expr-26.15 {error conditions} {
  390.     list [catch {expr a@b} msg] $msg
  391. } {1 {syntax error in expression "a@b"}}
  392. test expr-26.16 {error conditions} {
  393.     list [catch {expr a[b} msg] $msg
  394. } {1 {missing close-bracket}}
  395. test expr-26.17 {error conditions} {
  396.     list [catch {expr a`b} msg] $msg
  397. } {1 {syntax error in expression "a`b"}}
  398. test expr-26.18 {error conditions} {
  399.     list [catch {expr \"a\"\{b} msg] $msg
  400. } {1 {missing close-brace}}
  401. test expr-26.19 {error conditions} {
  402.     list [catch {expr a} msg] $msg
  403. } {1 {syntax error in expression "a"}}
  404.  
  405. # Cancelled evaluation.
  406.  
  407. test expr-27.1 {cancelled evaluation} {
  408.     set a 1
  409.     expr {0&&[set a 2]}
  410.     set a
  411. } 1
  412. test expr-27.2 {cancelled evaluation} {
  413.     set a 1
  414.     expr {1||[set a 2]}
  415.     set a
  416. } 1
  417. test expr-27.3 {cancelled evaluation} {
  418.     set a 1
  419.     expr {0?[set a 2]:1}
  420.     set a
  421. } 1
  422. test expr-27.4 {cancelled evaluation} {
  423.     set a 1
  424.     expr {1?2:[set a 2]}
  425.     set a
  426. } 1
  427. catch {unset x}
  428. test expr-27.5 {cancelled evaluation} {
  429.     list [catch {expr {[info exists x] && $x}} msg] $msg
  430. } {0 0}
  431. test expr-27.6 {cancelled evaluation} {
  432.     list [catch {expr {0 && [concat $x]}} msg] $msg
  433. } {0 0}
  434.  
  435. # Tcl_ExprBool as used in "if" statements
  436.  
  437. test expr-28.1 {Tcl_ExprBoolean usage} {
  438.     set a 1
  439.     if {2} {
  440.     set a 2
  441.     }
  442.     set a
  443. } 2
  444. test expr-28.2 {Tcl_ExprBoolean usage} {
  445.     set a 1
  446.     if {0} {
  447.     set a 2
  448.     }
  449.     set a
  450. } 1
  451. test expr-28.3 {Tcl_ExprBoolean usage} {
  452.     set a 1
  453.     if {1.2} {
  454.     set a 2
  455.     }
  456.     set a
  457. } 2
  458. test expr-28.4 {Tcl_ExprBoolean usage} {
  459.     set a 1
  460.     if {-1.1} {
  461.     set a 2
  462.     }
  463.     set a
  464. } 2
  465. test expr-28.5 {Tcl_ExprBoolean usage} {
  466.     set a 1
  467.     if {0.0} {
  468.     set a 2
  469.     }
  470.     set a
  471. } 1
  472. test expr-28.6 {Tcl_ExprBool usage} {
  473.     list [catch {if {"abc"} {}} msg] $msg
  474. } {1 {expression didn't have numeric value}}
  475.  
  476. # Operands enclosed in braces
  477.  
  478. test expr-29.1 {braces} {expr {{abc}}} abc
  479. test expr-29.2 {braces} {expr {{00010}}} 8
  480. test expr-29.3 {braces} {expr {{3.1200000}}} 3.12
  481. test expr-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
  482. test expr-29.5 {braces} {
  483.     list [catch {expr "\{abc"} msg] $msg
  484. } {1 {missing close-brace}}
  485.  
  486. # Very long values
  487.  
  488. test expr-30.1 {long values} {
  489.     set a "0000 1111 2222 3333 4444"
  490.     set a "$a | $a | $a | $a | $a"
  491.     set a "$a || $a || $a || $a || $a"
  492.     expr {$a}
  493. } {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444}
  494. test expr-30.2 {long values} {
  495.     set a "000000000000000000000000000000"
  496.     set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
  497.     expr $a
  498. } 5
  499.